package com.fufu.leetcode;

import java.util.Scanner;

/**
 * @author: BlcakTiger
 * @date: 2023/2/27 12:40
 * @contact: hsf6661@163.com
 */
public class 数字三角形 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] arr = new int[n+1][n+1];
        System.out.println("\n---------------初始化数组：---------------");
        for (int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                arr[i][j] = sc.nextInt();
            }
        }
        print(arr);

        System.out.println("--------------渐进变化----------------");

        for (int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                arr[i][j] += Math.max(arr[i-1][j],arr[i-1][j-1]);
                print(arr);
                System.out.println("local:("+i+","+j+") 左上:"+arr[i-1][j-1]+" 右上:"+arr[i-1][j]+" 当前值："+arr[i][j]);
                System.out.println("-----------------------------");
            }
        }

        System.out.println(arr[n][arr.length/2]);
    }

    public static void print(int[][] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int i1 = 0; i1 < arr[i].length; i1++) {
                System.out.print(arr[i][i1]+" ");
            }
            System.out.println();
        }
    }
}
